extends ../layout

block meta
    link(rel="stylesheet", href="#{options.cdn_path}/js/artDialog/skins/default.css?v=#{options.site_version}")
    style
        /*emotions*/
        .emotions{position:absolute;top:30px;left:20px;border:1px solid #AAA;padding:5px;background-color:#FFF;z-index:9999999;display:none}
        .emotions table td{padding:1px;}
        .emotions table td div{background: url("https://res.mail.qq.com/zh_CN//images/mo/DEFAULT2/default.gif") no-repeat 0 0 scroll transparent;width:24px;height:24px;cursor:pointer; border:1px solid #dfe6f6;}
        .emotions table div:hover{border:1px solid blue;}
        .emotions .emotionsGif{position:absolute;top:-1px;left:430px;border:1px solid #AAA;padding:20px;background-color:#FFF;text-align:center;width:24px;height:24px}

block content
    // 传递参数
    wechatClass = true
    tab = wxRule.id ? '修改规则' : '添加规则'
    include ../common/_admin_navbar
    .content
        .header
            h1.page-title #{tab}
        ul.breadcrumb
            li
                a(href="/admin") 首页
                span.divider /
            li.active #{tab}
        .container-fluid
            .row-fluid
                form(action="/admin/wechat/save_update", method="post")
                    input(type="hidden", name="wxRule.id", value="#{wxRule.id}")
                    .btn-toolbar
                        button.btn.btn-primary(type="submit")
                            i.icon-save 
                            | &nbsp;保存
                        a.btn(href="/admin/wechat") 返回
                        .btn-group
                    .well
                        #myTabContent.tab-content
                            label 规则
                            input.input-xlarge(type="text", name="wxRule.rule", value="#{wxRule.rule}", required="required")
                            label 回复
                                span  
                                    a.iconEmotion(href="javascript:;", inputid="rule")
                                        i.icon-hand-right
                                        | 表情
                            textarea#rule(name="wxRule.reply", style="width: 700px; height: 200px;") #{wxRule.reply}

                include ../common/_admin_footer
    .emotions

block script
    script(src="#{options.cdn_path}/js/artDialog/jquery.artDialog.min.js?v=#{options.site_version}")
    script(src="#{options.cdn_path}/js/emotions/emotions.js?v=#{options.site_version}")
    script
        $(function(){
            $('form').submit(function(){
                var dialog = $.dialog();
                var rule = $('input[name="wxRule.rule"]').val();
                var reply = $('textarea[name="wxRule.reply"]').val();
                if( rule.length < 1 ){
                    dialog.content('标题太短！').time(1000);
                    return false;
                }
                if( reply.length < 1 ){
                    dialog.content('亲再多些点吧！').time(1000);
                    return false;
                }
                _post(this, dialog, function(data){
                    if(data.status){
                        dialog.content('保存成功！').lock().time(1000);
                        setTimeout(function(){
                            location.href = '/admin/wechat';
                        }, 1500);
                    }else{
                        dialog.content('服务器忙，请稍候！').lock().time(2000);
                    }
                });
                return false;
            });
        });